# -*- coding=utf-8-*-
"""
@File:memory_selection
@Author:Created by Han X.Y
@Date:on 2021/7/7 14:56 
"""

def Roman_to_integer(roman_string):
    """
    将罗马字符串转换成整数

    IV--->IV0
    """
    roman_integer_dict={
        'I':1,
        "V":5,
        "X":10,
        "L":50,
        "C":100,
        "D":500,
        "M":1000
    }
    #从最右边开始检索
    #初始比较位0
    num,lastint,total=0,0,0
    for i in range(len(roman_string)):
        #从右边开始取数
        char=roman_string[len(roman_string)-(i+1):len(roman_string)-i]
        #将对应的罗马数字转换成整数
        num=roman_integer_dict[char]
        print(f'char={char},num={num}')
        #右大左小
        if num<lastint:
            total-=num
        else:
            # 左大右小
            total+=num
        lastint=num
    return total
